package com.xiaoxiong.mami.dao.mapperImpl;

import org.apache.ibatis.jdbc.SQL;

public class GoodMapperProvider {

    public String insertGood(String goodsId, String title, Double price, String goodsDesc,
                                  String images, String thumbUrl, Integer sort, String status,
                                  String goodsImages, Integer stock, String setMeal,
                                  Integer buyNumMax, String goodsNumber) {
        SQL sql = new SQL();
        sql.INSERT_INTO("goods");

        if (goodsId != null) {
            sql.VALUES("goodsId", "#{goodsId}");
        }

        if (title != null) {
            sql.VALUES("title", "#{title}");
        }

        if (price != null) {
            sql.VALUES("price", "#{price}");
        }

        if (goodsDesc != null) {
            sql.VALUES("goodsDesc", "#{goodsDesc}");
        }

        if (images != null) {
            sql.VALUES("images", "#{images}");
        }

        if (thumbUrl != null) {
            sql.VALUES("thumbUrl", "#{thumbUrl}");
        }

        if (sort != null) {
            sql.VALUES("sort", "#{sort}");
        }

        if (status != null) {
            sql.VALUES("status", "#{status}");
        }

        if (goodsImages != null) {
            sql.VALUES("goodsImages", "#{goodsImages}");
        }

        if (setMeal != null){
            sql.VALUES("setMeal", "#{setMeal}");
        }

        if (buyNumMax != null){
            sql.VALUES("buyNumMax", "#{buyNumMax}");
        }

        if (stock != null){
            sql.VALUES("stock", "#{stock}");
        }

        if (goodsNumber != null){
            sql.VALUES("goodsNumber", "#{goodsNumber}");
        }

        sql.VALUES("updateTime", "now()");
        sql.VALUES("createTime", "now()");

        return sql.toString();
    }


    public String updateGoods(String goodsId, String title, Double price, String goodsDesc,
                             String images, String thumbUrl, Integer sort, String status,
                             String goodsImages, Integer stock, String setMeal,
                             Integer buyNumMax, String goodsNumber) {
        SQL sql = new SQL();
        sql.UPDATE("goods");


        if (title!= null) {
            sql.SET("title = #{title,jdbcType=VARCHAR}");
        }

        if (price!= null) {
            sql.SET("price = #{price,jdbcType=DOUBLE}");
        }

        if (goodsDesc != null) {
            sql.SET("goodsDesc = #{goodsDesc,jdbcType=VARCHAR}");
        }

        if (images != null) {
            sql.SET("images = #{images,jdbcType=VARCHAR}");
        }

        if (thumbUrl != null) {
            sql.SET("thumbUrl = #{thumbUrl,jdbcType=VARCHAR}");
        }

        if (sort != null) {
            sql.SET("sort = #{sort,jdbcType=INTEGER}");
        }

        if (status != null) {
            sql.SET("status = #{status,jdbcType=VARCHAR}");
        }

        if (goodsImages != null) {
            sql.SET("goodsImages = #{goodsImages,jdbcType=VARCHAR}");
        }

        if (stock != null) {
            sql.SET("stock = #{stock,jdbcType=INTEGER}");
        }

        if (setMeal != null) {
            sql.SET("setMeal = #{setMeal,jdbcType=VARCHAR}");
        }

        if (buyNumMax != null) {
            sql.SET("buyNumMax = #{buyNumMax,jdbcType=INTEGER}");
        }

        if (goodsNumber!= null) {
            sql.SET("goodsNumber = #{goodsNumber,jdbcType=VARCHAR}");
        }

        sql.SET("updateTime = now()");

        sql.WHERE("goodsId = #{goodsId,jdbcType=VARCHAR}");

        return sql.toString();
    }

}
